import { AfterViewChecked, ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { Istudent } from 'src/app/istudent';

@Component({
  selector: 'app-student',
  templateUrl: './student.component.html',
  styleUrls: ['./student.component.scss'],
  // 就是只有当输入数据(即@Input)的引用发生变化或者有事件触发时，
  // 组件才进行变化检测。这种策略检查不彻底，但效率高。
  // changeDetection:ChangeDetectionStrategy.OnPush
})
export class StudentComponent implements AfterViewChecked {
  // @Input()
  // selectedSexyValue='2';
  // @Input自定义属性绑
  @Input()
  student:Istudent={
    img: '',
    name: '',
    age: 0,
    intersting: [],
    shuxue: 0,
    yuwen: 0,
    yinyu: 0,
    pingjun: 0,
    zongchegnji: 0,
    beizhu: '',
    sexy: ''
  };

  zongchegnji:number=0;
  // @Output自定义事件绑定
  @Output()
  selectClick:EventEmitter<Istudent>=new EventEmitter<Istudent>();

  // 点击事件 选中学生
  studentImgClick(item:Istudent){
    this.selectClick.emit(item);
  }


  // 求平均分
  getpingjun:(student:Istudent)=>string=(student)=>{
    let result:string= ((student.shuxue+student.yuwen+student.yinyu)/3).toFixed(2);
    return result;
  }
  // 总分
  setTotal:(student:Istudent)=>void=(student)=>{
    this.zongchegnji= ((student.shuxue+student.yuwen+student.yinyu));
  }
  ngAfterViewChecked(){

    console.log("studentComponent----ngAfterViewChecked");

  }

   onchage=function(event:any,obj:any){
    console.log(event);
    console.log(obj);
    console.log(event.target.value);
    
    // alert("error!");
    
  }

}
